package com.wechatapp.mengyao.poetry.controller;

import com.wechatapp.mengyao.poetry.core.PageResult;
import com.wechatapp.mengyao.poetry.core.RestResponse;
import com.wechatapp.mengyao.poetry.dto.ClearPlaybackHistoryDTO;
import com.wechatapp.mengyao.poetry.dto.UpdatePlayBackHistoryDTO;
import com.wechatapp.mengyao.poetry.service.PlaybackHistoryService;
import com.wechatapp.mengyao.poetry.vo.PlaybackHistoryView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author yanghuaxu
 * @date 2025/7/12 10:22
 */
@RestController
@RequestMapping("/api/v1/playback_history")
public class PlaybackHistoryController {

    @Autowired
    private PlaybackHistoryService playbackHistoryService;

    @GetMapping("/page")
    public RestResponse<PageResult<PlaybackHistoryView>> getPlaybackHistoryByUserId(@RequestParam Map<String, String> map) {

        return RestResponse.ok(playbackHistoryService.getPlaybackHistoryByUserId(map));
    }

    @PutMapping("")
    public RestResponse<Object> updateUserPlaybackHistory(@RequestBody @Validated UpdatePlayBackHistoryDTO updatePlayBackHistory) {
        playbackHistoryService.updateUserPlaybackHistory(updatePlayBackHistory);
        return RestResponse.ok(null);
    }

    @PostMapping("/clear")
    public RestResponse<Integer> clearPlaybackHistory(@RequestBody @Validated ClearPlaybackHistoryDTO clearPlaybackHistory) {
        return RestResponse.ok(playbackHistoryService.clearPlaybackHistory(clearPlaybackHistory));
    }

}
